package tasks;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/**
 * https://wiki.amoscloud.com/zh/ProgramingPractice/NowCoder/Adecco/Topic0006
 *
 */
public class Task06 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] split = scanner.nextLine().split("\\s+");
        if (split == null || split.length != 2) {
            return;
        }
        int highValue = Integer.parseInt(split[0]);
        int n = Integer.parseInt(split[1]);

        String[] highValueArray = scanner.nextLine().split("\\s+");
        List<Integer> list = new ArrayList<>();
        for (String s : highValueArray) {
            list.add(Integer.parseInt(s));
        }

        list.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                int d1 = Math.abs(o1 - highValue);
                int d2 = Math.abs(o2 - highValue);
                if (d1 == d2) {
                    return o1 - o2;
                } else {
                    return d1 - d2;
                }
            }
        });
        for (Integer integer : list) {
            System.out.print(integer + " ");
        }
    }
}
